<#assign pageName="新增机构信息">
<@override name="page-content">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>${pageName}</legend>
    </fieldset>
    <form class="layui-form padding-10" lay-filter="formDepartmentAdd">
        <@ctrl.TreeSelect path="department.upperId" dataList=depList fieldText="depName" 
            fieldValue="depId" labelText="上级单位" fieldParentID="upperId" 
            parentidValue="${(dep.upperId)!'-1'}" required="required">
        </@ctrl.TreeSelect>
        <@ctrl.Textbox path="department.depCode" labelText="机构编码" required="required"/>
        <@ctrl.Textbox path="department.depName" labelText="机构名称" required="required"/>
        <@ctrl.SingleSelect path="department.depType" options={'1':'无','R':'地区','C':'公司','D':'部门','G':'团队'} labelText="机构类型" />
        <div>
            <div class="layui-inline">
                <@ctrl.Textbox path="department.principal" labelText="负责人"/>
            </div>
            <div class="layui-inline">
                <@ctrl.Textbox path="department.phone" labelText="联系电话" />
            </div>
            <div class="layui-inline">
                <@ctrl.Textbox path="department.mobil" labelText="手机号码" required="phone"/>
            </div>
            <div class="layui-inline">
                <@ctrl.Textbox path="department.postNo" labelText="邮政编码"/>
            </div>
        </div>
        <div>
            <div class="layui-inline">
                <@ctrl.SingleSelect path="department.provinceNo" labelText="所在区域" options=listPro![] text="name" value="id">
                    <option value="000000">请选择省</option>
                </@ctrl.SingleSelect>
            </div>
            <div class="layui-inline">
                <@ctrl.SingleSelect path="department.cityNo" labelText="所在市" labelShow=false options=listCity![] text="name" value="id">
                    <option value="000000">请选择市</option>
                </@ctrl.SingleSelect>
            </div>
            <div class="layui-inline">
                <@ctrl.SingleSelect path="department.regionNo" labelText="所在县(区)" labelShow=false options=listRegin![] text="name" value="id">
                    <option value="000000">请选择县/区</option>
                </@ctrl.SingleSelect>
            </div>
        </div>
        <@ctrl.Textbox path="department.address" labelText="详细地址" />
        <@ctrl.Textarea path="department.remark" labelText="备注说明" />
        <@ctrl.Hidden path="department.guid" value="${guid}"/>
        <@ctrl.Hidden path="department.areaNo"/>
        <@ctrl.Hidden path="department.jsm"/>
        <@ctrl.Hidden path="department.province" />
        <@ctrl.Hidden path="department.city" />
        <@ctrl.Hidden path="department.region" />
        <@ctrl.FormAction backURL="../management?gid=${guid}"/>
    </form>
</@override>
<@override name="page-scripts">
    <script>
      $(function(){
          layui.use(['form','layer', 'jquery'], function(){
              var form = layui.form;
              var layer=layui.layer;
              $=layui.jquery;
              //监听提交
              form.on('submit(submit)', function(data){
                  submitData(data.field, '${contextPath}/admin/department/add', function(){location.href="${contextPath}/admin/department/management?gid=${guid}";});
                  return false;
              });

              /* 拼音码获取 */
              $("input[name='depName']").blur(function(e){
                 var depName = this.value ;
                 $.post(
                     '${rc.getContextPath()}/common/getpycode.do',{hz:depName},
                     function(result){
                         $("input[name='jsm']").val(result);
                     },'text'
                 ); 
             }); 
             
             /* 区域三级联动 */
             form.on('select(provinceNo)', function(data){
                  var proValue = data.value;
                  proValue = (proValue.length==6)?proValue:"000000";
                  var proText = (proValue!="000000")?data.elem[data.elem.selectedIndex].text:"";
                  var $city = "<option value='000000'>请选择市</option>";
                  var $region = "<option value='000000'>请选择县/区</option>";
                  if(proValue!="000000"){
                      $.post('${rc.getContextPath()}/codetable/city/'+proValue.substring(0,2)+'/query', {}, 
                          function(data){
                          $.each(data, function(index, item){
                              $city += "<option value='" + item.id + "'>" + item.name + "</option>";
                          })
                          $("#cityNo").html($city);
                          $("#regionNo").html($region);
                          form.render("select");
                      })
                  }
                  $("#province").val(proText);
                  $("#cityNo").trigger("change");
              });
              form.on('select(cityNo)',function(data){
                  var cityValue =  data.value;
                  cityValue = (cityValue.length==6)?cityValue:"000000";
                  var cityText = (cityValue!="000000")?data.elem[data.elem.selectedIndex].text:"";
                  var $region = "<option value='000000'>请选择县/区</option>";
                  if(cityValue!="000000"){
                      $.post('${rc.getContextPath()}/codetable/region/'+cityValue.substring(0,4)+'/query', {}, 
                          function(data){
                          $.each(data, function(index, item){
                              $region += "<option value='" + item.id + "'>" + item.name + "</option>";
                          })
                          $("#regionNo").html($region);
                          form.render("select");
                      })
                  }
                  $("#city").val(cityText);
                  $("#regionNo").trigger("change");
              });
              form.on('select(regionNo)', function(data){
                  var regionValue =  data.value;
                  regionValue = (regionValue.length==6)?regionValue:"000000";
                  var regionText = (regionValue!="000000")?data.elem[data.elem.selectedIndex].text:"";
                  $("#region").val(regionText);
                  $("#areaNo").val(regionValue);
                  $("#address").val($("#province").val()+$("#city").val()+regionText);
              });
          })
      })
    </script>
</@override>
<@extends name="/layout/basepage.html"/> 
